<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>title</title>
	</head>

	<body>
		<h1>mvc模式控制</h1>
		<fieldset>
			<legend>input</legend>
			<div>name: <input type="text" value="tim" id="name-i" /></div>
		</fieldset>
		<fieldset>
			<legend>output</legend>
			<div>name: <span id="name-o"></span></div>
		</fieldset>
		<button onclick="controller.updateName()">update name</button>
		<button onclick="controller.changeNameToTom()">change name to tom</button>
		<script type="text/javascript">
			var namei = document.getElementById('name-i');
			var nameo = document.getElementById('name-o');

			var model = {
				name: 'tim'
			}

			var controller = {
				updateName: function() {
					model.name = namei.value;
					nameo.innerText = model.name;
				},
				changeNameToTom:function () {
					model.name="tom";
					namei.value = model.name;
					nameo.innerText = model.name;
				}
			}
			controller.updateName();
		</script>
	</body>

</html>